<?php 
 defined('_JEXEC') or die('Restricted access');
 //echo $_SESSION['id_a_b'];
 //echo $_SESSION['id_user'];
   // echo "vao dc";
 ?> 
<script>
$(document).ready(function(){
    //check ratio
    $("#day").click(function(){
        $('#datepicker').removeAttr('disabled');
        $('#cbo_month').attr('disabled', 'disable');
        $('#op_def').attr('selected', 'select');
        //$("#month").attr('checked','null');
        //alert($("#day").val());
    });
    
    $("#month").click(function(){
        $('#cbo_month').removeAttr('disabled');
        $('#datepicker').attr('disabled', 'disable');
        $('#datepicker').val('');
        
    });
    
    });
</script>
<script>
    function sub(b)
    {
        var flag =0;
        document.frm1['type'].value = b;
        if(b=='soon')
        {
            var c = document.frm1['datepicker'].value;
            var d  =document.frm1['cbo_month'].value;
            if(c=='' && d =='0')
            {
                alert("Bạn chưa chọn giá trị");
                flag = 1;
            }
            else if(c != '')
            {
                document.frm1['layout'].value = 'soon_date';
            }
            else if(d != '')
            {
                document.frm1['layout'].value = 'soon_month';
            }
        }
        
        if(b=='late')
        {
            var c = document.frm1['datepicker'].value;
            var d  =document.frm1['cbo_month'].value;
            if(c=='' && d =='0')
            {
                alert("Bạn chưa chọn giá trị");
                flag = 1;
            }
            else if(c != '')
            {
                document.frm1['layout'].value = 'late_date';
            }
            else if(d != '')
            {
                document.frm1['layout'].value = 'late_month';
            }
            
            
        }
        if(flag==0){
        document.frm1.submit();}
        
    }
    
    $(function() {
        $( "#datepicker" ).datepicker();
    });

</script>

<table>
    <tr>
        
            <td><form action="index.php?option=com_work_point" method="post" name="frm1">
                        <input type="hidden" name="option" id="option" value="com_work_point" />
                        <input name="task" type="hidden" />
                        <input type="hidden" name="view" id="view" value="report" />
                        <input type="hidden" name="layout" />
                         <input type="hidden" name="type" />
                <input type="button" value="Ði trễ" onclick="sub('late')" />
                
            </td>
            <td>
            <input type="radio" name="abc" value="1" id="day"/>Ngày <input type="text" id="datepicker" name="datepicker" disabled="disable" />
            </td>
            <td>
            <input type="radio" name="abc" value="2" id="month" />Tháng 
            <select disabled="disable" id="cbo_month" name="cbo_month">
                <option value="0" selected="selected" id="op_def">Chọn tháng</option>
                <?php 
                    for($i = 1;$i<=12;$i++)
                    {
                        ?>
                            <option value="<?php echo $i; ?>">Tháng <?php echo $i; ?></option>
                        <?php
                    }
                ?>
            </select>
            </td>
        
    </tr>
    <tr>
        <td><input type="button" value="Về sớm" onclick="sub('soon')" /></td>
    </tr>
    <tr><td>
        <input type="button" value="Nghỉ" /></td>
    </tr>

</table></form>
<?php 
    if(isset($this->data))
    {
?>
    <div class="content">
        <table border="1">
            <tr>
                <td>
                    Mã nhân viên
                </td>
                <td>
                    Họ Tên
                </td>
                <td>
                    Thời gian 
                </td>
            </tr>
            <?php 
                $type = '';
                foreach($this->data as $row)
                {
                        $x = substr($row->Time,11,8);
                        $x = strtotime($x);
                        $y = strtotime($row->outtime);
                    if($type != $row->id_employee)
                    {
                        if($x < $y)
                        {
                        ?>
                            <tr>
                                <td>
                                    <?php echo $row->id_employee;?>
                                </td>
                                <td>
                                    <?php echo $row->name;?>
                                </td>
                                <td>
                                    <?php echo $row->Time;
                                        
                                    ?>
                                </td>
                            </tr>
                        <?php
                        
                        }
                        
                    }
                    $type = $row->id_employee;
                    //else
                    //{
                        //continue;
                    //}
                }
            ?>
        </table>
    </div>
<?php 
}
?>